home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / scroll.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.9 KB  |  142 lines

  1. //
  2. // "$Id: scroll.cxx,v 1.4 1999/01/07 19:18:00 mike Exp $"
  3. //
  4. // Fl_Scroll test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Double_Window.H>
  28. #include <FL/Fl_Scroll.H>
  29. #include <FL/Fl_Toggle_Button.H>
  30. #include <FL/Fl_Choice.H>
  31. #include <FL/Fl_Box.H>
  32. #include <string.h>
  33. #include <stdio.h>
  34. #include <FL/fl_draw.H>
  35. #include <FL/math.h>
  36.  
  37. class Drawing : public Fl_Widget {
  38.   void draw();
  39. public:
  40.   Drawing(int X,int Y,int W,int H,const char* L) : Fl_Widget(X,Y,W,H,L) {
  41.     align(FL_ALIGN_TOP);
  42.     box(FL_FLAT_BOX);
  43.     color(FL_WHITE);
  44.   }
  45. };
  46.  
  47. void Drawing::draw() {
  48.   draw_box();
  49.   fl_push_matrix();
  50.   fl_translate(x()+w()/2, y()+h()/2);
  51.   fl_scale(w()/2, h()/2);
  52.   fl_color(FL_BLACK);
  53.   for (int i = 0; i < 20; i++) {
  54.     for (int j = i+1; j < 20; j++) {
  55.       fl_begin_line();
  56.       fl_vertex(cos(M_PI*i/10+.1), sin(M_PI*i/10+.1));
  57.       fl_vertex(cos(M_PI*j/10+.1), sin(M_PI*j/10+.1));
  58.       fl_end_line();
  59.     }
  60.   }
  61.   fl_pop_matrix();
  62. }
  63.  
  64. Fl_Scroll* thescroll;
  65.  
  66. void box_cb(Fl_Widget* o, void*) {
  67.   thescroll->box(((Fl_Button*)o)->value() ? FL_DOWN_FRAME : FL_NO_BOX);
  68.   thescroll->redraw();
  69. }
  70.  
  71. void type_cb(Fl_Widget*, void* v) {
  72.   thescroll->type(int(v));
  73.   thescroll->redraw();
  74. }
  75.  
  76. Fl_Menu_Item choices[] = {
  77.   {"0", 0, type_cb, (void*)0},
  78.   {"HORIZONTAL", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL},
  79.   {"VERTICAL", 0, type_cb, (void*)Fl_Scroll::VERTICAL},
  80.   {"BOTH", 0, type_cb, (void*)Fl_Scroll::BOTH},
  81.   {"HORIZONTAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::HORIZONTAL_ALWAYS},
  82.   {"VERTICAL_ALWAYS", 0, type_cb, (void*)Fl_Scroll::VERTICAL_ALWAYS},
  83.   {"BOTH_ALWAYS", 0, type_cb, (void*)Fl_Scroll::BOTH_ALWAYS},
  84.   {0}
  85. };
  86.  
  87. void align_cb(Fl_Widget*, void* v) {
  88.   thescroll->scrollbar.align(int(v));
  89.   thescroll->redraw();
  90. }
  91.  
  92. Fl_Menu_Item align_choices[] = {
  93.   {"left+top", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_TOP)},
  94.   {"left+bottom", 0, align_cb, (void*)(FL_ALIGN_LEFT+FL_ALIGN_BOTTOM)},
  95.   {"right+top", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_TOP)},
  96.   {"right+bottom", 0, align_cb, (void*)(FL_ALIGN_RIGHT+FL_ALIGN_BOTTOM)},
  97.   {0}
  98. };
  99.  
  100. int main(int argc, char** argv) {
  101.   Fl_Window window(5*75,400);
  102.   window.box(FL_NO_BOX);
  103.   Fl_Scroll scroll(0,0,5*75,300);
  104.  
  105.   int n = 0;
  106.   for (int y=0; y<16; y++) for (int x=0; x<5; x++) {
  107.     char buf[20]; sprintf(buf,"%d",n++);
  108.     Fl_Button* b = new Fl_Button(x*75,y*25+(y>=8?5*75:0),75,25,strdup(buf));
  109.     b->color(n);
  110.     b->labelcolor(FL_WHITE);
  111.   }
  112.   Drawing drawing(0,8*25,5*75,5*75,0);
  113.   scroll.end();
  114.   window.resizable(scroll);
  115.  
  116.   Fl_Box box(0,300,5*75,window.h()-300); // gray area below the scroll
  117.   box.box(FL_FLAT_BOX);
  118.  
  119.   Fl_Toggle_Button but1(150, 310, 200, 25, "box");
  120.   but1.callback(box_cb);
  121.   
  122.   Fl_Choice choice(150, 335, 200, 25, "type():");
  123.   choice.menu(choices);
  124.   choice.value(3);
  125.  
  126.   Fl_Choice achoice(150, 360, 200, 25, "scrollbar.align():");
  127.   achoice.menu(align_choices);
  128.   achoice.value(3);
  129.  
  130.   thescroll = &scroll;
  131.  
  132.   //scroll.box(FL_DOWN_BOX);
  133.   //scroll.type(Fl_Scroll::VERTICAL);
  134.   window.end();
  135.   window.show(argc,argv);
  136.   return Fl::run();
  137. }
  138.  
  139. //
  140. // End of "$Id: scroll.cxx,v 1.4 1999/01/07 19:18:00 mike Exp $".
  141. //
  142.